home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / OutOfContextMenus / Source / CFlipBehavior.cp < prev    next >
Encoding:
Text File  |  1999-06-23  |  2.0 KB  |  85 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CFlipBehavior.cp                 ©1999 Eric Traut
  3. // ===========================================================================
  4.  
  5. #include "CFlipBehavior.h"
  6. #include "CShadowWindow.h"
  7.  
  8.  
  9. // ---------------------------------------------------------------------------
  10. //        • CFlipBehavior
  11. // ---------------------------------------------------------------------------
  12.  
  13. CFlipBehavior::CFlipBehavior(
  14.     CShadowWindow &        inShadowWindow,
  15.     Boolean                inHorizontal)
  16.     :    COffscreenBehavior(inShadowWindow, true)
  17. {
  18.     mHorizontal = inHorizontal;
  19. }
  20.  
  21.  
  22. // ---------------------------------------------------------------------------
  23. //        • RenderToGWorld
  24. // ---------------------------------------------------------------------------
  25.  
  26. Boolean
  27. CFlipBehavior::RenderToGWorld(
  28.     StGWorldLocker &        inBackingLocker,
  29.     StGWorldLocker &        inRenderingLocker)
  30. {
  31.     UInt16        row;
  32.     UInt16        column;
  33.     UInt16        maxRow;
  34.     UInt16        maxColumn;
  35.     UInt16        srcRowWords;
  36.     UInt16        destRowWords;
  37.     UInt16 *    srcRowPtr;
  38.     UInt16 *    destRowPtr;
  39.     PixMapPtr    tempPixMap;
  40.     
  41.     tempPixMap = *inBackingLocker.GetPixMap();
  42.     srcRowWords = (tempPixMap->rowBytes & 0x3FFF) / 2;
  43.     srcRowPtr = reinterpret_cast<UInt16 *>(tempPixMap->baseAddr);
  44.  
  45.     tempPixMap = *inRenderingLocker.GetPixMap();
  46.     destRowWords = (tempPixMap->rowBytes & 0x3FFF) / 2;
  47.     destRowPtr = reinterpret_cast<UInt16 *>(tempPixMap->baseAddr);
  48.  
  49.     maxRow = tempPixMap->bounds.bottom - tempPixMap->bounds.top;
  50.     maxColumn = tempPixMap->bounds.right - tempPixMap->bounds.left;
  51.  
  52.     if (mHorizontal)
  53.     {
  54.         // Flip horizontal
  55.         for (row = 0; row < maxRow; row++)
  56.         {
  57.             for (column = 0; column < maxColumn; column++)
  58.             {
  59.                 destRowPtr[column] = srcRowPtr[maxColumn - column - 1];
  60.             }
  61.             
  62.             srcRowPtr += srcRowWords;
  63.             destRowPtr += destRowWords;
  64.         }
  65.     }
  66.     else
  67.     {
  68.         // Flip vertical
  69.         for (column = 0; column < maxColumn; column++)
  70.         {
  71.             for (row = 0; row < maxRow; row++)
  72.             {
  73.                 destRowPtr[row * destRowWords] = srcRowPtr[(maxRow - row - 1) * srcRowWords];
  74.             }
  75.             
  76.             srcRowPtr++;
  77.             destRowPtr++;
  78.         }
  79.     }
  80.     
  81.     return true;
  82. }
  83.  
  84.  
  85.